﻿using System;
using System.Web;

namespace PmfWeb.Core.HttpHandlers
{
    class NoLinks : IHttpModule
    {
        public void Init(HttpApplication context)
        {
            context.BeginRequest += context_BeginRequest;
        }

        private void context_BeginRequest(object sender, EventArgs e)
        {
            HttpApplication app = sender as HttpApplication;
            HttpContext context = app.Context;

            string path = context.Request.PhysicalPath;
            string serverHost = context.Request.Url.Host;
            Uri u = context.Request.UrlReferrer;
            if (u == null || u.Host.ToLower() != serverHost.ToLower())
            {
                context.Response.WriteFile("~/default.gif");
            }
            else
            {
                context.Response.WriteFile(path);
            }
        }

        public void Dispose()
        {
        }
    }
}
